<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Pegawai extends Admin_Controller
{
	public function __construct(){
		parent::__construct();
		$this->module = strtolower(__CLASS__);	
		check_user('Pegawai');
	}
	
	public function index()
	{		
		check_user('Data pegawai');
		$allow_edit_pegawai= check_user('Edit pegawai',false);
		$allow_add_pegawai= check_user('Tambah pegawai',false);
		$allow_delete_pegawai= check_user('Delete pegawai',false);
		
		
		$this->crud->set_table('sp_pegawai');
		$this->crud->set_primary_key('pegawai_id');
		$this->crud->set_subject('Data pegawai');
		$this->crud->required_fields('nip'
									,'nip_lama'
									,'nama'
									,'jenis_kelamin'
									,'tempat_lahir'
									,'tanggal_lahir'
									,'agama'
									,'alamat'
									,'kodepos'
									,'jenis_pegawai'
									,'kedudukan_pegawai'
									,'status_pegawai'
									,'photo_pegawai'
									,'no_akta_lahir'
									,'no_identitas'
									,'gol_darah'
									,'berat_badan'
									,'tinggi_badan'
									,'warna_kulit'
									,'status_kepemilikan_rumah'
									);
		$this->crud->set_field_upload('photo_pegawai','files/pegawai');
		$this->crud->set_relation('jenis_kelamin','sp_jenis_kelamin','jk_nama');		
		$this->crud->set_relation('agama','sp_agama','agama_nama');	
		$this->crud->set_relation('jenis_pegawai','sp_jenis_pegawai','jenis_pegawai');	
		$this->crud->set_relation('kedudukan_pegawai','sp_kedudukan_pegawai','kedudukan_pegawai');
		$this->crud->set_relation('status_pegawai','sp_status_pegawai','status_name');
		$this->crud->set_relation('status_kepemilikan_rumah','sp_status_kepemilikan_rumah','status_rmh_name');
		//$this->crud->set_relation('tempat_lahir','sp_lokasi','lokasi_nama',array('jenis' => 'P'));
		$this->crud->columns('id','nip','nama','gelar_depan','gelar_belakang','alamat');
		
		$this->crud->callback_add_field('tempat_lahir', array($this,'tempat_lokasi'));

		if( !$allow_add_pegawai ){
			$this->crud->unset_add();
		}
		
		if( !$allow_edit_pegawai ){
			$this->crud->unset_edit();
		}
		
		if( !$allow_delete_pegawai ){
			$this->crud->unset_delete();
		}
		
		$this->crud->add_action('Data riwayat', $this->icon->fa['tags'], 'pegawai/riwayat','ui-icon-plus');
		$this->crud->set_field_upload('image','files/pegawai');
		$output = $this->crud->render();
		
		$data['output'] = $output;
		$data['page'] = "pegawai_data";
		$data['module'] = $this->module;
		$this->load->view($this->layout_content,$data);		
	}
	
	public function tempat_lokasi() {

		$qs = '
		<script>
		$(document).ready(function(){			
			var pusat;
			$("#lokasi_pusat").live( "change",function(){
					pusat = $(this).val();					
					getDataOption(pusat,"KB");
				});			
		});

		function getDataOption(idlokasi,jenis){
			var lokasi;
			if(jenis == "KB"){
				lokasi = "kabupaten";
			}else{
				lokasi = "kecamatan";
			}
			
			$.ajax({
					url : "'.site_url('pegawai/get_data_kabupaten').'",
					type: "POST",
					data : {idlok:idlokasi,jenislok:jenis},
					success: function(data)
					{
						$(".lokasi_"+lokasi).html(data);
					}
				});
		}
		</script>
		';
			
        $r = $this->adodb->GetAll("SELECT * FROM sp_lokasi WHERE jenis = 'P'");
        //$r = $q->result_array();

        $sel = '';
        $sel .= '<div class="lokasi_pusat" style="float: left;"><select name="tempat_lahir_pusat" id="lokasi_pusat">';
        foreach($r as $k => $v){
        	$sel .= '<option value="'.$v['no_id'].'">'.$v['lokasi_nama'].'</option>';
        }
		$sel .= '</select></div>';

		$sel .= '<div class="lokasi_kabupaten" style="float: left;"></div>';
		
		return $qs.$sel;
        
    }

    public function get_data_kabupaten(){
    	
    	if($_POST['jenislok'] == 'KB'){    		
    		$idsel = 'lokasi_kabupaten';
    	}else{    		
    		$idsel = 'lokasi_kecamatan';
    	}

    	$kodecepat = $this->adodb->GetOne("SELECT cepat_kode FROM sp_lokasi WHERE no_id = ".$_POST['idlok']);
    	$kode 	   = substr($kodecepat, 0,3);
    	
    	$r = $this->adodb->GetAll("SELECT * FROM sp_lokasi WHERE jenis = '".$_POST['jenislok']."' AND cepat_kode LIKE '$kode%'");
    	$sel = '';
        $sel .= '<select name="tempat_lahir" id="'.$idsel.'">';
        foreach($r as $k => $v){
        	$sel .= '<option value="'.$v['no_id'].'">'.$v['lokasi_nama'].'</option>';
        }
		$sel .= '</select>';

    	echo $sel;
    }

    public function riwayat(){
    	//$data['output'] = $output;
    	
    	$id = $this->uri->segment(3);

    	//$this->crud->set_table('sp_pegawai');
    	//$this->crud->where('pegawai_id',$id);
		//$this->crud->set_subject('Data pegawai');
		//$output = $this->crud->render();
    	
    	$this->load->model('pegawai/pegawai_model');
    	$pegawai = $this->pegawai_model->get_data_pegawai($id);
    	//$data['output']	= $output;
    	$data['personal']	= $pegawai;
		$data['page'] = "pegawai_riwayat";
		$data['module'] = $this->module;
		$data['page_title'] = "Data Pegawai";

		$arrbreadcrumb = array("Home" => 'pegawai/index'
							  ,"Riwayat Pegawai" => '');
		$data['breadcrumb'] = $arrbreadcrumb;

		$this->load->view('pegawai_separator_data',$data);
		$this->load->view('pegawai_detail_data',$data);
		$data['page_title'] = "Riwayat Pegawai";
		$arrbreadcrumb = array();
		$data['breadcrumb'] = $arrbreadcrumb;	
		$this->load->view('pegawai_separator_data',$data);
		$this->load->view($this->layout_content,$data);			

    }

    public function riwayat_pendidikan(){
    	   
    	$arrbreadcrumb = array();

    	$id = $this->uri->segment(3);

    	$this->crud->set_table('sp_riwayat_pendidikan');
    	
    	$this->crud->set_primary_key('riwayat_pend_id');
    	$state = $this->crud->getState();
	    $state_info = $this->crud->getStateInfo();
	 	
	    $this->crud->columns('pendidikan','tanggal_lulus','tahun_lulus','nomor_ijazah','nama_sekolah','gelar_depan','gelar_belakang','status_pendidikan');

	    $this->crud->set_relation('pendidikan','sp_pendidikan','pendidikan_nama');
	    $this->crud->set_relation('status_pendidikan','sp_status_pendidikan','status_pendidikan_nama');

	    if($state == 'add')
	    {
	        //Do your cool stuff here . You don't need any State info you are in add
	        $this->crud->field_type('pns_id', 'hidden', $id);
	        $this->crud->field_type('riwayat_pend_id', 'hidden', '');
	    }
		$this->crud->set_subject('Data Riwayat Pendidikan');

		$this->crud->unset_read();

		$this->crud->where('pns_id',$id);

		$output = $this->crud->render();
    	
    	$this->load->model('pegawai/pegawai_model');
    	$pegawai = $this->pegawai_model->get_data_pegawai($id);
    	$data['output']	= $output;
    	$data['personal']	= $pegawai;
		$data['page'] = "pegawai_data";
		$data['module'] = $this->module;
		$data['page_title'] = "Data Pegawai";

		$arrbreadcrumb = array("Home" => 'pegawai/index'
							  ,"Riwayat Pegawai" => 'pegawai/riwayat/'.$id
							  ,"Riwayat Pendidikan" => '');
		$data['breadcrumb'] = $arrbreadcrumb;

		$this->load->view('pegawai_separator_data',$data);
		$this->load->view('pegawai_detail_data',$data);
		$data['page_title'] = "Riwayat Pendidikan";
		$arrbreadcrumb = array();
		$data['breadcrumb'] = $arrbreadcrumb;	
		$this->load->view('pegawai_separator_data',$data);
		$this->load->view($this->layout_content,$data);	

		

    }

    public function riwayat_golongan(){
    	   
    	$arrbreadcrumb = array();

    	$id = $this->uri->segment(3);

    	$this->crud->set_table('sp_riwayat_golongan');
    	
    	$this->crud->set_primary_key('riwayat_gol_id');
    	$state = $this->crud->getState();
	    $state_info = $this->crud->getStateInfo();
	 	
	    $this->crud->columns('kode_jenis_kp','golongan_id','nomor_sk','tanggal_sk','nomor_bkn','tanggal_bkn','tmt_golongan','masa_kerja_tahun','masa_kerja_bulan','angka_kredit_utama','angka_kredit_tambahan');

	    $this->crud->set_relation('kode_jenis_kp','sp_kenaikan_pangkat','kp_nama');
	    $this->crud->set_relation('golongan_id','sp_pangkat_golongan','{golongan_kode} - {golongan_nama}');

	    $this->crud->display_as('kode_jenis_kp','Jenis KP');
	    $this->crud->display_as('golongan_id','Golongan');

	    if($state == 'add')
	    {
	        //Do your cool stuff here . You don't need any State info you are in add
	        $this->crud->field_type('pns_id', 'hidden', $id);
	        $this->crud->field_type('riwayat_gol_id', 'hidden', '');
	    }
		$this->crud->set_subject('Data Riwayat Golongan');

		$this->crud->unset_read();

		$this->crud->where('pns_id',$id);

		$output = $this->crud->render();
    	
    	$this->load->model('pegawai/pegawai_model');
    	$pegawai = $this->pegawai_model->get_data_pegawai($id);
    	$data['output']	= $output;
    	$data['personal']	= $pegawai;
		$data['page'] = "pegawai_data";
		$data['module'] = $this->module;
		$data['page_title'] = "Data Pegawai";

		$arrbreadcrumb = array("Home" => 'pegawai/index'
							  ,"Riwayat Pegawai" => 'pegawai/riwayat/'.$id
							  ,"Riwayat Golongan" => '');
		$data['breadcrumb'] = $arrbreadcrumb;

		$this->load->view('pegawai_separator_data',$data);
		$this->load->view('pegawai_detail_data',$data);
		$data['page_title'] = "Riwayat Golongan";
		$arrbreadcrumb = array();
		$data['breadcrumb'] = $arrbreadcrumb;	
		$this->load->view('pegawai_separator_data',$data);
		$this->load->view($this->layout_content,$data);
    }

    public function riwayat_jabatan(){
    	   
    	$arrbreadcrumb = array();

    	$id = $this->uri->segment(3);

    	$this->crud->set_table('sp_riwayat_jabatan');
    	
    	$this->crud->set_primary_key('riwayat_jabatan_id');
    	$state = $this->crud->getState();
	    $state_info = $this->crud->getStateInfo();
	 	
	    $this->crud->columns('id_unor','id_jenis_jabatan','id_jabatan','id_eselon','tmt_jabatan','nomor_sk','tanggal_sk','tmt_pelantikan');

	    $this->crud->set_relation('id_unor','sp_unor','nama_unor');
	    $this->crud->set_relation('id_jenis_jabatan','sp_jenis_jabatan','jabatan_nama');
	    $this->crud->set_relation('id_jabatan','sp_jenjang_jabatan','nama');
	    $this->crud->set_relation('id_eselon','sp_pangkat_golongan','golongan_kode');

	    if($state == 'add')
	    {	    	
	        //Do your cool stuff here . You don't need any State info you are in add
	        $this->crud->field_type('pns_id', 'hidden', $id);
	        $this->crud->field_type('riwayat_jabatan_id', 'hidden', '');
	    }

	    $this->crud->display_as('id_unor','UNOR');
	    $this->crud->display_as('id_jenis_jabatan','Jenis Jabatan');
	    $this->crud->display_as('id_jabatan','Jabatan');
	    $this->crud->display_as('id_eselon','Eselon');

		$this->crud->set_subject('Data Riwayat Jabatan');

		//$this->crud->unset_read();

		$this->crud->where('pns_id',$id);

		$output = $this->crud->render();
    	
    	$this->load->model('pegawai/pegawai_model');
    	$pegawai = $this->pegawai_model->get_data_pegawai($id);
    	$data['output']	= $output;
    	$data['personal']	= $pegawai;
		$data['page'] = "pegawai_data";
		$data['module'] = $this->module;
		$data['page_title'] = "Data Pegawai";

		$arrbreadcrumb = array("Home" => 'pegawai/index'
							  ,"Riwayat Pegawai" => 'pegawai/riwayat/'.$id
							  ,"Riwayat Jabatan" => '');
		$data['breadcrumb'] = $arrbreadcrumb;

		$this->load->view('pegawai_separator_data',$data);
		$this->load->view('pegawai_detail_data',$data);
		$data['page_title'] = "Riwayat Jabatan";
		$arrbreadcrumb = array();
		$data['breadcrumb'] = $arrbreadcrumb;	
		$this->load->view('pegawai_separator_data',$data);
		$this->load->view($this->layout_content,$data);
    }

    public function riwayat_hukuman(){
    	$arrbreadcrumb = array();

    	$id = $this->uri->segment(3);

    	$this->crud->set_table('sp_riwayat_hukuman');

    	$this->crud->set_primary_key('riwayat_hukum_id');
    	$state = $this->crud->getState();
	    $state_info = $this->crud->getStateInfo();

	    $this->crud->columns('golongan_id','jenis_hukum_id','nomor_sk','tanggal_sk','tanggal_mulai_hukum','tanggal_akhir_hukum','masa_tahun','masa_bulan','nomor_pp','nomor_pp','nomor_sk_batal','tanggal_sk_batal');
	    
	    $this->crud->set_relation('golongan_id','sp_pangkat_golongan','golongan_kode');	    
	    $this->crud->set_relation('jenis_hukum_id','sp_jenis_hukuman','{tingkat_hukum_kode} - {jenis_hukum_nama}');

	    if($state == 'add')
	    {	    	
	        //Do your cool stuff here . You don't need any State info you are in add
	        $this->crud->field_type('pns_id', 'hidden', $id);
	        $this->crud->field_type('riwayat_hukum_id', 'hidden', '');
	    }

	    $this->crud->display_as('golongan_id','Golongan');
	    $this->crud->display_as('jenis_hukum_id','Jenis Hukuman');

	    $this->crud->set_subject('Data Riwayat Hukuman');

		//$this->crud->unset_read();

		$this->crud->where('pns_id',$id);

		$output = $this->crud->render();
    	
    	$this->load->model('pegawai/pegawai_model');
    	$pegawai = $this->pegawai_model->get_data_pegawai($id);
    	$data['output']	= $output;
    	$data['personal']	= $pegawai;
		$data['page'] = "pegawai_data";
		$data['module'] = $this->module;
		$data['page_title'] = "Data Pegawai";

		$arrbreadcrumb = array("Home" => 'pegawai/index'
							  ,"Riwayat Pegawai" => 'pegawai/riwayat/'.$id
							  ,"Riwayat Hukuman" => '');
		$data['breadcrumb'] = $arrbreadcrumb;

		$this->load->view('pegawai_separator_data',$data);
		$this->load->view('pegawai_detail_data',$data);
		$data['page_title'] = "Riwayat Hukuman";
		$arrbreadcrumb = array();
		$data['breadcrumb'] = $arrbreadcrumb;	
		$this->load->view('pegawai_separator_data',$data);
		$this->load->view($this->layout_content,$data);
    }	

    public function riwayat_cltn(){
    	$arrbreadcrumb = array();

    	$id = $this->uri->segment(3);

    	$this->crud->set_table('sp_riwayat_cltn');

    	$this->crud->set_primary_key('riwayat_cltn_id');
    	$state = $this->crud->getState();
	    $state_info = $this->crud->getStateInfo();

	    $this->crud->columns('cltn_id','ked_hukum_id','nomor_sk_cltn','tanggal_sk_cltn','tanggal_awal_cltn','tanggal_akhir_cltn','tanggal_aktif_cltn','nomor_bkn','tanggal_bkn');
	    
	    $this->crud->set_relation('cltn_id','sp_cltn','cltn_nama');	    	    

	    if($state == 'add')
	    {	    	
	        //Do your cool stuff here . You don't need any State info you are in add
	        $this->crud->field_type('pns_id', 'hidden', $id);
	        $this->crud->field_type('riwayat_cltn_id', 'hidden', '');
	    }

	    $this->crud->display_as('cltn_id','CLTN');
	    $this->crud->display_as('ked_hukum_id','Kedudukan Hukuman');

	    $this->crud->set_subject('Data Riwayat CLTN');

		//$this->crud->unset_read();

		$this->crud->where('pns_id',$id);

		$output = $this->crud->render();
    	
    	$this->load->model('pegawai/pegawai_model');
    	$pegawai = $this->pegawai_model->get_data_pegawai($id);
    	$data['output']	= $output;
    	$data['personal']	= $pegawai;
		$data['page'] = "pegawai_data";
		$data['module'] = $this->module;
		$data['page_title'] = "Data Pegawai";

		$arrbreadcrumb = array("Home" => 'pegawai/index'
							  ,"Riwayat Pegawai" => 'pegawai/riwayat/'.$id
							  ,"Riwayat CLTN" => '');
		$data['breadcrumb'] = $arrbreadcrumb;

		$this->load->view('pegawai_separator_data',$data);
		$this->load->view('pegawai_detail_data',$data);
		$data['page_title'] = "Riwayat CLTN";
		$arrbreadcrumb = array();
		$data['breadcrumb'] = $arrbreadcrumb;	
		$this->load->view('pegawai_separator_data',$data);
		$this->load->view($this->layout_content,$data);
    }

    public function riwayat_angka_kredit(){
    	$arrbreadcrumb = array();

    	$id = $this->uri->segment(3);

    	$this->crud->set_table('sp_riwayat_angka_kredit');

    	$this->crud->set_primary_key('riwayat_kredit_id');
    	$state = $this->crud->getState();
	    $state_info = $this->crud->getStateInfo();

	    $this->crud->columns('angka_kredit_pertama','jabatan_id','nomor_sk','tanggal_sk','bulan_mulai_penilaian','tahun_mulai_penilaian','bulan_selesai_penilaian','tahun_selesai_penilaian','kredit_utama_baru','kredit_penunjang_baru','kredit_baru_total');
	    
	    $this->crud->set_relation('jabatan_id','sp_jenjang_jabatan','nama');	    

	    $this->crud->callback_add_field('bulan_mulai_penilaian', array($this,'get_bulan_mulai'));
	    $this->crud->callback_add_field('tahun_mulai_penilaian', array($this,'get_tahun_mulai'));
	    $this->crud->callback_add_field('bulan_selesai_penilaian', array($this,'get_bulan_selesai'));
	    $this->crud->callback_add_field('tahun_selesai_penilaian', array($this,'get_tahun_selesai'));


	    if($state == 'add')
	    {	    	
	        //Do your cool stuff here . You don't need any State info you are in add
	        $this->crud->field_type('pns_id', 'hidden', $id);
	        $this->crud->field_type('riwayat_kredit_id', 'hidden', '');
	    }

	    $this->crud->display_as('jabatan_id','jabatan');

	    $this->crud->set_subject('Data Riwayat Angka Kredit');

		//$this->crud->unset_read();

		$this->crud->where('pns_id',$id);

		$output = $this->crud->render();
    	
    	$this->load->model('pegawai/pegawai_model');
    	$pegawai = $this->pegawai_model->get_data_pegawai($id);
    	$data['output']	= $output;
    	$data['personal']	= $pegawai;
		$data['page'] = "pegawai_data";
		$data['module'] = $this->module;
		$data['page_title'] = "Data Pegawai";

		$arrbreadcrumb = array("Home" => 'pegawai/index'
							  ,"Riwayat Pegawai" => 'pegawai/riwayat/'.$id
							  ,"Riwayat Angka Kredit" => '');
		$data['breadcrumb'] = $arrbreadcrumb;

		$this->load->view('pegawai_separator_data',$data);
		$this->load->view('pegawai_detail_data',$data);
		$data['page_title'] = "Riwayat Angka Kredit";
		$arrbreadcrumb = array();
		$data['breadcrumb'] = $arrbreadcrumb;	
		$this->load->view('pegawai_separator_data',$data);
		$this->load->view($this->layout_content,$data);
    }

    public function get_bulan_mulai() {       
    	 return $this->bulan('bulan_mulai_penilaian');
    }

    public function get_bulan_selesai() {       
    	 return $this->bulan('bulan_selesai_penilaian');
    }

    public function bulan($namesel){

        $sel = '';
        $sel .= '<select name="'.$namesel.'">';
        for($i = 1; $i <= 12; $i++){
        	$sel .= '<option value="'.$i.'">'.$i.'</option>';
        }
		$sel .= '</select>';
		
		return $sel;
    }

    public function get_tahun_mulai() {       
    	 return $this->tahun('tahun_mulai_penilaian',20,5);
    }

    public function get_tahun_selesai() {       
    	 return $this->tahun('tahun_selesai_penilaian',5,20);
    }

    public function tahun($namesel,$tahunmulai = 0,$tahunselesai = 0){

    	$date_awal = date("Y") - $tahunmulai;
    	$date_akhir = date("Y") + $tahunselesai;
        $sel = '';
        $sel .= '<select name="'.$namesel.'">';
        for($i = $date_awal; $i <= $date_akhir; $i++){
        	$sel .= '<option value="'.$i.'">'.$i.'</option>';
        }
		$sel .= '</select>';
		
		return $sel;
    }

    public function riwayat_kursus(){
    	$arrbreadcrumb = array();

    	$id = $this->uri->segment(3);

    	$this->crud->set_table('sp_riwayat_kursus');

    	$this->crud->set_primary_key('riwayat_kursus_id');
    	$state = $this->crud->getState();
	    $state_info = $this->crud->getStateInfo();

	    $this->crud->columns('nama_kursus','jumlah_jam','tanggal_kursus','tahun_kursus','kode_instansi_id','institusi_penyelenggara','tipe_kursus','nomor_sertifikat');
	    
	    $this->crud->set_relation('kode_instansi_id','sp_instansi','instansi');	    
	    $this->crud->callback_add_field('tipe_kursus', array($this,'get_tipe_kursus'));
	    $this->crud->callback_edit_field('tipe_kursus', array($this,'get_tipe_kursus_edit'));

	    if($state == 'add')
	    {	    	
	        //Do your cool stuff here . You don't need any State info you are in add
	        $this->crud->field_type('pns_id', 'hidden', $id);
	        $this->crud->field_type('riwayat_kursus_id', 'hidden', '');
	        $this->crud->field_type('kursus_id', 'hidden', '');
	    }

	    if($state == 'edit')
	    {
	    	 $this->crud->field_type('kursus_id', 'hidden', '');
	    }

	    $this->crud->display_as('kode_instansi_id','Instansi');
	    $this->crud->display_as('tipe_kursus','Tipe (K=Kursus/S=Sertifikat)');

	    $this->crud->set_subject('Data Riwayat Kursus');

		//$this->crud->unset_read();

		$this->crud->where('pns_id',$id);

		$output = $this->crud->render();
    	
    	$this->load->model('pegawai/pegawai_model');
    	$pegawai = $this->pegawai_model->get_data_pegawai($id);
    	$data['output']	= $output;
    	$data['personal']	= $pegawai;
		$data['page'] = "pegawai_data";
		$data['module'] = $this->module;
		$data['page_title'] = "Data Pegawai";

		$arrbreadcrumb = array("Home" => 'pegawai/index'
							  ,"Riwayat Pegawai" => 'pegawai/riwayat/'.$id
							  ,"Riwayat Kursus" => '');
		$data['breadcrumb'] = $arrbreadcrumb;

		$this->load->view('pegawai_separator_data',$data);
		$this->load->view('pegawai_detail_data',$data);
		$data['page_title'] = "Riwayat Kursus";
		$arrbreadcrumb = array();
		$data['breadcrumb'] = $arrbreadcrumb;	
		$this->load->view('pegawai_separator_data',$data);
		$this->load->view($this->layout_content,$data);
    }

    public function get_tipe_kursus(){
    	
        $sel = '';
        $sel .= '<select name="tipe_kursus">';        
        $sel .= '<option value="K">Kursus</option>'; 
        $sel .= '<option value="S">Sertifikat</option>';       
		$sel .= '</select>';
		
		return $sel;
    }

    public function get_tipe_kursus_edit($value, $primary_key){
    	
    	$selk = ($value == 'K')?"selected = selected" : "";
    	$sels = ($value == 'S')?"selected = selected" : "";

        $sel = '';
        $sel .= '<select name="tipe_kursus">';        
        $sel .= '<option value="K" '.$selk.'>Kursus</option>'; 
        $sel .= '<option value="S" '.$sels.'>Sertifikat</option>';       
		$sel .= '</select>';
		
		return $sel;
    }

    public function riwayat_diklat(){
    	$arrbreadcrumb = array();

    	$id = $this->uri->segment(3);

    	$this->crud->set_table('sp_riwayat_diklat');

    	$this->crud->set_primary_key('riwayat_diklat_id');
    	$state = $this->crud->getState();
	    $state_info = $this->crud->getStateInfo();

	    $this->crud->columns('jenis_diklat_id','diklat_id_struktural','nama_diklat','tgl_mulai','tgl_selesai','nomor_sertifikat','jml_pjl','penyelenggara');
	    
	    $this->crud->set_relation('jenis_diklat_id','sp_jenis_diklat','jenis_diklat');
	    $this->crud->set_relation('diklat_id_struktural','sp_diklat_struktural','jenis_diklat_struktural');	    
	    #$this->crud->callback_add_field('diklat_id_struktural', array($this,'jenis_diklat'));	    
	    #$this->crud->callback_add_field('nama_diklat', array($this,'diklat_nama_diklat'));

	    if($state == 'add')
	    {	    	
	        //Do your cool stuff here . You don't need any State info you are in add
	        $this->crud->field_type('pns_id', 'hidden', $id);
	        $this->crud->field_type('riwayat_diklat_id', 'hidden', '');	       
	    }

	    $this->crud->display_as('jenis_diklat_id','Jenis Diklat');
	    $this->crud->display_as('diklat_id_struktural','Diklat Struktural');

	    $this->crud->set_subject('Data Riwayat Diklat');

		//$this->crud->unset_read();

		$this->crud->where('pns_id',$id);

		$output = $this->crud->render();
    	
    	$this->load->model('pegawai/pegawai_model');
    	$pegawai = $this->pegawai_model->get_data_pegawai($id);
    	$data['output']	= $output;
    	$data['personal']	= $pegawai;
		$data['page'] = "pegawai_data";
		$data['module'] = $this->module;
		$data['page_title'] = "Data Pegawai";

		$arrbreadcrumb = array("Home" => 'pegawai/index'
							  ,"Riwayat Pegawai" => 'pegawai/riwayat/'.$id
							  ,"Riwayat Diklat" => '');
		$data['breadcrumb'] = $arrbreadcrumb;

		$this->load->view('pegawai_separator_data',$data);
		$this->load->view('pegawai_detail_data',$data);
		$data['page_title'] = "Riwayat Diklat";
		$arrbreadcrumb = array();
		$data['breadcrumb'] = $arrbreadcrumb;	
		$this->load->view('pegawai_separator_data',$data);
		$this->load->view($this->layout_content,$data);
    }

    public function jenis_diklat() {

		$qs = '
		<script>
		$(document).ready(function(){			
			var jenis;
			$("#field-jenis_diklat_id").live( "change",function(){
					jenis = $(this).val();					
					if(jenis == 1){
						$("#field-diklat_id_struktural").removeAttr("disabled");
					}else{
						$("#field-diklat_id_struktural").attr("disabled","disabled");

					}
				});			
		});		
		</script>
		';
			
        $r = $this->adodb->GetAll("SELECT * FROM sp_diklat_struktural");
        //$r = $q->result_array();

        $sel = '<div class="diklatstruktural">';
        $sel .= '<select name="diklat_id_struktural" id="field-diklat_id_struktural">';
        $sel .= '<option value="">Silahkan Pilih Jenis Diklat Struktural</option>';
        foreach($r as $k => $v){
        	$sel .= '<option value="'.$v['id'].'">'.$v['jenis_diklat_struktural'].'</option>';
        }
		$sel .= '</select></div';
		
		return $qs.$sel;
        
    }

    
}